import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'my_calendar_detail_model.dart';
class MyCalendarDetailController extends GetxController{



  var calendar_id;

  /// 修改日程状态

  requestDataWithState(var state)async{

    var params = {
      'calendar_id':Get.arguments,
      'state':state,
    };

    var json = await DioManager().kkRequest(Address.calendarEventState,bodyParams: params);

    BotToast.showText(text: json['message']);

  }
  //确认弹窗
   confirmDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text("温馨提示"),
          content: const Text("您确定要删除当前日程？"),
          actions: <Widget>[
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: const Text("取消"),
            ),
            TextButton(
              child: const Text("确定"),
              onPressed: () async {
                var params = {
                  'calendar_id':calendar_id,
                };
                var json = await DioManager().kkRequest(Address.calendarUnlink,bodyParams: params);
                Get.back(result: 'refresh');
                Get.back(result: 'refresh');
                BotToast.showText(text: json['message']);
              },
            ),
          ],
        );
      },
    );
  }

  /// 删除日程
  requestDataWithUnlink()async{
    confirmDialog(Get.overlayContext!);

    // var params = {
    //   'calendar_id':Get.arguments,
    // };
    // var json = await DioManager().kkRequest(Address.calendarUnlink,bodyParams: params);
    // Get.back(result: 'refresh');
    // BotToast.showText(text: json['message']);
  }




  /// 获取详情
  ///
  ///

   MyCalendarDetailModel? model;

  requestDataWithDetail()async{

    var json = await DioManager().kkRequest('${Address.calendarRead}/${Get.arguments}',method: 'get');

    MyCalendarDetailModel _model = MyCalendarDetailModel.fromJson(json);

    model = _model;

    update();

  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    calendar_id = Get.arguments;
    requestDataWithDetail();
  }
}